package xyz.xxpc.springcloud.provider.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.xxpc.springcloud.pojo.User;
import xyz.xxpc.springcloud.provider.dao.UserDao;
import xyz.xxpc.springcloud.service.api.UserService;

import java.util.List;

@RestController
public class UserController implements UserService {
    private UserDao userDao;

    @Autowired
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public List<User> queryAll() {
        return userDao.getAll();
    }

    @Override
    public User query(Integer id) {
        User user = userDao.getById(id);
        if(null == user){
            throw new RuntimeException("没有找到对应用户");
        }
        return user;
    }

    @Override
    public User add(User user) {
        userDao.insert(user);
        return user;
    }

}
